<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Examples;
use App\Http\Controllers\Controller;
use App\Models\AdvType;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Controllers\Dashboard;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Illuminate\Support\Facades\URL;

class BaseAdvContentController extends AdminController
{
    public $advTypeId = 0;
    public $advType;

    public function __construct(){
        $url = URL::full();
        preg_match('/adv_content\/([\s\S]*?)\/manage/', $url, $urlData);
        $this->advTypeId = $urlData[1];
        $this->advType = AdvType::find($this->advTypeId);
    }

    public function index(Content $content)
    {
        return $content
            ->header($this->advType->adv_type_name)
            ->description('列表')
            ->breadcrumb($this->advType->adv_type_name)
            ->body($this->grid());
    }

    public function create(Content $content)
    {
        return $content
            ->header($this->advType->adv_type_name)
            ->description('列表')
            ->breadcrumb($this->advType->adv_type_name)
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    public function grid()
    {
        return AdvContentController::grid($this->advTypeId);
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    public function form()
    {
        return AdvContentController::form($this->advTypeId);
    }
}
